package com.juicygames.shmup.player;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.Log;

import com.juicygames.framework.action.DrawAction;
import com.juicygames.framework.exception.GamePartNotFound;
import com.juicygames.framework.gamepart.GameHandler;
import com.juicygames.framework.property.space.ColorProperty;
import com.juicygames.framework.property.space.Position;
import com.juicygames.framework.type.Circle;

public class DrawHandler extends GameHandler<DrawAction> {
	private static final String LOGTAG = DrawHandler.class.getName();
	
	Position position;
		
	public void load() {
		position = parent.getPart(Position.class);
	}
	
	public Class<DrawAction> getActionClassHandled() {
		return DrawAction.class;
	}
	
	public void handle(DrawAction draw) {
		
//		Log.d(LOGTAG,"Drawing player");
		
		Canvas canvas = draw.getCanvas();
		
		try {
			
			Circle c = new Circle();
			c.x = position.get().x;
			c.y = position.get().y;
			c.radius = 20;
			
			Path circlePath = new Path(); 
			circlePath.addCircle(c.x, c.y, c.radius, Path.Direction.CW);
			
			Paint paint = new Paint();
			paint.setColor(parent.getPart(ColorProperty.class).get());
			paint.setAlpha(255); 
			
			canvas.drawPath(circlePath, paint); 

		} catch (GamePartNotFound e) {
			Log.e("UpdateHandler.handle(...)", "", e);
		}
	}

}
